package day05;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import day05.Caidanlei.BackgroundPanel;

public class Kaoshilei extends JFrame {
	Container ct;//创建一个容器
	BackgroundPanel bgp;//创建背景画板
	JLabel j1=new JLabel("国家一级人才考试系统");		
	JLabel j2=new JLabel("考生信息");
	JTextArea j3=new JTextArea("多行文本域");
    Option a = new Option(0, "A");
	Option b = new Option(1, "B");
	Option c = new Option(2, "C");
	Option d = new Option(3, "D");
	JButton j5=new JButton("上一题");
	JButton j6=new JButton("下一题");
	JButton j7=new JButton("交卷");
	JLabel j8=new JLabel("题目数量");
	JLabel j9=new JLabel("剩余时间");
	// 选项集合, 方便答案读取的处理
		private Option[] options = new Option[4];


	private ClientContext clientcontext;
	
	public ClientContext getClientcontext() {
		return clientcontext;
	}
	public void setClientcontext(ClientContext clientcontext) {
		this.clientcontext = clientcontext;
	}
	
	Kaoshilei(){
		 init();
		 
		 this.setTitle("到考试界面了弟弟");
	     this.setResizable(false);
	     this.setSize(800, 600);
	     this.setLocationRelativeTo(null);
	     this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//	     this.setVisible(true);
	 }
	void init(){
		ct=this.getContentPane();
		bgp=new BackgroundPanel((new ImageIcon("风景3.jpg")).getImage());
        this.setLayout(null);
        bgp.setBounds(0,0,800,600);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //标题标签
        j1.setBounds(240, 10, 400, 30);//x坐标10，y坐标0，组件宽100，高50
        j1.setFont(new Font("宋体",Font.BOLD,30));
        j1.setForeground(new Color(0,255,127));
        //考生信息
        j2.setBounds(5, 20, 770, 100);
        j2.setFont(new Font("黑体",Font.BOLD,19));
        j2.setForeground(new Color(255,105,180));
        //题目框
        j3.setBounds(5,85, 770,340);
        j3.setFont(new Font("宋体",Font.BOLD,25));
        j3.setLineWrap(true);

        //多选按钮

		
		options[0] = a;
		options[1] = b;
		options[2] = c;
		options[3] = d;
        a.setBounds(240, 440, 36, 20);
        a.setFont(new Font("宋体",Font.BOLD,20));
        b.setBounds(300, 440, 36, 20);
        b.setFont(new Font("宋体",Font.BOLD,20));
        c.setBounds(360, 440, 36, 20);
        c.setFont(new Font("宋体",Font.BOLD,20));
        d.setBounds(420, 440, 36, 20);
        d.setFont(new Font("宋体",Font.BOLD,20));
        //上一题按钮
        j5.setBounds(200, 490, 90, 50);
        j5.setFont(new Font("宋体",Font.BOLD,15));
		j5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				clientcontext.upquestion();

			}
		});
        //下一题按钮
        j6.setBounds(355, 490, 90, 50);
        j6.setFont(new Font("宋体",Font.BOLD,15));	
		j6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				clientcontext.downquestion();

			}
		});
        //交卷按钮
        j7.setBounds(500, 490, 90, 50);
        j7.setFont(new Font("宋体",Font.BOLD,15));
		j7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				clientcontext.showsorce();

			}
		});

        //题目数量文本
        j8.setBounds(20, 500, 150, 15);
        j8.setFont(new Font("宋体",Font.BOLD,15));
        
        //剩余时间文本
        j9.setBounds(630, 502, 200, 17);
        j9.setFont(new Font("宋体",Font.BOLD,15));
        j9.setForeground(Color.red);
        this.add(j1);
        this.add(j2);
        this.add(j3);

        this.add(j5);
        this.add(j6);
        this.add(j7);
        this.add(j8);
        this.add(j9);
        this.add(a);
        this.add(b);
        this.add(c);
        this.add(d);
        ct.add(bgp,new Integer(Integer.MIN_VALUE));
        
	}
	public void updatequestion(String str) {
		j3.setText(str);
	}
	public void updateamount(int index ) {
		j8.setText("题目数量：20/"+index);
	}
	public void updateinformation(String str) {
		j2.setText(str);
	}
	
	/** 使用内部类扩展了 JCheckBox 增加了val 属性, 代表答案值 */
	class Option extends JCheckBox {
		private static final long serialVersionUID = 5569918347028393191L;

		int value;

		public Option(int val, String txt) {
			super(txt);
			this.value = val;
		}
	}
	//获得用户答案
	public ArrayList<Integer> getUserAnswers() {
		ArrayList<Integer> list = new ArrayList<Integer>();
		for (Option option : options) {
			if (option.isSelected()) {
				list.add(option.value);
			}
		}
		return list;
	}
    class BackgroundPanel extends JPanel{
       	Image im;
       	public BackgroundPanel(Image im)
       	{
       		this.im=im;
       		this.setOpaque(true);
       	}
       	
       	public void paintComponent(Graphics g)
       	{
       		super.paintComponents(g);
       		g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);
       		
       	}

       }
	


	}
//	private JLabel timer;
//	public void updateTime(long h, long m, long s) {
//		String time = h + ":" + m + ":" + s;
//		if (m < 5) {
//			timer.setForeground(new Color(0xC85848));
//		} else {
//			timer.setForeground(Color.blue);
//		}
//		timer.setText(time);
//	}
//	public void showTime(long h, long m, long s) {
//		String t = "剩余时间:" + h + ":" + m + ":" + s;
//		if (h == 0 && m < 5) {
//			timer.setForeground(Color.red);
//		}
//		timer.setText(t);
//	}


	





